module TextInputView where

import Graphics.UI.Gtk
import Graphics.UI.Gtk.ModelView as MV

data ViewState = V 
    {
      mainWidget :: Widget
    , executeB :: Button
    , exitCodeL :: Label
    , textView :: TextView
    , cancelB :: Button
    }

new buf fileButtons = do  
  cmdE <- textViewNewWithBuffer buf

  let stateTypes = [StateNormal, StateActive, StatePrelight, StateSelected, StateInsensitive]
      fgCols = [Color 65535 49152 0, Color  65535 49152 0, Color  65535 49152 0, Color  65535 49152 0]
      bgCols = [Color 255 192 0, Color 0 0 0, Color 0 0 0, Color 32535 32535 0]

  mapM_ (uncurry (widgetModifyText cmdE)) $
             stateTypes `zip` fgCols

  mapM_ (uncurry (widgetModifyBase cmdE)) $
             stateTypes `zip` bgCols

  scrollWin <- scrolledWindowNew Nothing Nothing
  set scrollWin 
          [ containerBorderWidth := 5
          , scrolledWindowShadowType := ShadowIn
          , scrolledWindowVscrollbarPolicy := PolicyAutomatic
          , scrolledWindowHscrollbarPolicy  := PolicyAutomatic
          ]
  containerAdd scrollWin cmdE
  

  cmdBHbox <- hBoxNew False 2
  cmdRunB <- buttonNewFromStock stockExecute
  boxPackEnd cmdBHbox cmdRunB PackNatural 2
             
  cancB <- buttonNewFromStock stockCancel
  widgetSetSensitivity cancB False
  boxPackEnd cmdBHbox cancB PackNatural 2
             
  boxPackStart cmdBHbox fileButtons PackNatural 2

  exitL <- labelNew Nothing
  boxPackStart cmdBHbox exitL PackGrow 2

  centerHB <- hBoxNew False 2
  
  cmdVbox <- vBoxNew False 2
  boxPackStart cmdVbox scrollWin PackGrow 2
  boxPackStart cmdVbox cmdBHbox PackNatural 2  

  vbox <- vBoxNew False 2
  boxPackStart vbox  cmdVbox PackGrow 2

  return $ V (toWidget vbox) cmdRunB exitL cmdE cancB


-- some Utility functions for working with a text View